﻿@model ECMS.AppService.Model.Models.RouteTemplateModel
@{
    Layout = null;
}
<div class="layui-body-header">
    <ul class="kit-breadcrumb">
        <li class="kit-item">
            <a href="#/">
                <i class="layui-icon">&#xe68e;</i>
                <span>首页</span>
            </a>
        </li>
        <li class="kit-separator">
            <i class="layui-icon">&#xe602;</i>
        </li>
        <li class="kit-item">
            <a href="#/routetemplate/list">
                <i class="layui-icon">&#xe658;</i>
                <span>路由模板管理</span>
            </a>
        </li>
        <li class="kit-separator">
            <i class="layui-icon">&#xe602;</i>
        </li>
        <li class="kit-item">
            <a>
                <span>新增路由模板</span>
            </a>
        </li>
    </ul>
</div>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <a href="javascript:history.back(-1);" title="返回"><i class="layui-icon">&#xe65c;</i></a>
                    @{
                        var showName = Model.Id == 0 ? "新增" : "编辑";
                    }
                    <span>@showName</span>
                </div>
                <div class="layui-card-body">
                    <form class="layui-form" action="">
                        <input type="hidden" name="id" value="@Model.Id" />
                        <input type="hidden" name="guid" value="@Model.Guid" />
                        @Html.AntiForgeryToken()
                        <div class="layui-form-item">
                            <label class="layui-form-label">模板名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" required lay-verify="required" value="@Model.Name" placeholder="请输入名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">模板地址</label>
                            <div class="layui-input-block">
                                <input type="text" name="component" required lay-verify="required" value="@Model.Component" placeholder="请输入模板地址" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">路径</label>
                            <div class="layui-input-block">
                                <input type="text" name="path" required lay-verify="required" value="@Model.Path" placeholder="请输入路径" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 脚本 -->
<script>
    layui.use(['form', 'axios'], function () {
        var form = layui.form,
            axios = layui.axios,
            layer = layui.layer;
        form.render();

        //监听提交
        form.on('submit(formDemo)', function (data) {
            var layIndex = layer.load(2, {
                shade: [0.2, '#393D49']
            });
            console.log(data);
            axios.post('/RouteTemplate/Save', data.field)
                .then(function (response) {
                    if (response.status === 500) {
                        console.log(response);
                        throw new Error(response.statusText);
                    }
                    return response.data;
                })
                .then(function (res) {
                    layer.msg(res.message);
                    layer.close(layIndex);
                    if (res.success) {
                        location.href = "#/routetemplate/list";
                    }
                })
                .catch(function (err) {
                    console.log(err);
                    layer.close(layIndex);
                });

            return false;
        });
    });
</script>
<!-- 样式 -->
<style scoped>
</style>
